package com.leoman.service.impl;

import com.leoman.core.Constant;
import com.leoman.dao.UserSealInfoDao;
import com.leoman.entity.UserSealInfo;
import com.leoman.service.UserSealInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * UserSealInfoServiceImpl
 * Created by 涂奕恒 on 2016/12/6 0006 下午 2:18.
 */
@Service
public class UserSealInfoServiceImpl implements UserSealInfoService {

    @Autowired
    private UserSealInfoDao userSealInfoDao;

    @Override
    public List<UserSealInfo> findAll() {
        return userSealInfoDao.findAll();
    }

    @Override
    public Page<UserSealInfo> find(int pageNum, int pageSize) {
        return userSealInfoDao.findAll(new PageRequest(pageNum - 1, pageSize, Sort.Direction.DESC, "id"));
    }

    @Override
    public Page<UserSealInfo> find(int pageNum) {
        return find(pageNum, Constant.PAGE_DEF_SIZE);
    }

    @Override
    public UserSealInfo getById(int id) {
        return userSealInfoDao.findOne(id);
    }

    @Override
    public void deleteById(int id) {
        userSealInfoDao.delete(id);
    }

    @Override
    public UserSealInfo create(UserSealInfo userSealInfo) {
        return userSealInfoDao.save(userSealInfo);
    }

    @Override
    public UserSealInfo update(UserSealInfo userSealInfo) {
        return userSealInfoDao.save(userSealInfo);
    }

    @Override
    @Transactional
    public void deleteAll(int[] ids) {
        for (int id : ids) {
            deleteById(id);
        }
    }

    @Override
    public List<UserSealInfo> findListByUserId(Integer userId) {
        return userSealInfoDao.findListByUserId(userId);
    }
}